import configparser
import logging
import os

# 读取配置文件
def read_config():
    config_path = os.path.join(os.path.dirname(__file__), 'config')
    print(f"Config file path: {config_path}")  # 打印文件路径
    if not os.path.exists(config_path):
        raise FileNotFoundError(f"Config file {config_path} not found.")
    config = configparser.ConfigParser()
    config.read(config_path)
    return config

# 设置日志记录
def setup_logging(log_file):
    logging.basicConfig(
        filename=log_file,
        level=logging.INFO,
        format='%(asctime)s - %(levelname)s - %(message)s'
    )
    logging.info(f"Logging configured with log file: {log_file}")

# 获取配置
try:
    config = read_config()
    setup_logging(config['settings']['log_file'])
except KeyError as e:
    logging.error(f"Key error: {e}")
except Exception as e:
    logging.error(f"Unexpected error: {e}")
